<?php
$accountObj = new account();  

//$accountShowRs = $accountObj->show('show create table account', true);
//print_r($accountShowRs);

$accountsRs = $accountObj->getAll("`uid` > 0");
//print_r($accountsRs);
$viewObj = new View(true, 10);
$viewObj->template_dir    = APP_PATH.'/views/'; 
$viewObj->compile_dir     = APP_PATH.'/views_c/';
$viewObj->cache_dir       = APP_PATH.'/cache/';
$viewObj->caching = false;
$viewObj->cache_lifetime = 3;

$cacheid = '7788788';
$mem = new Memcache;
$mem->connect('127.0.0.1', 11211);
//$mem->set($cacheid, 'This is a test!', 0, 60);
//$val = $mem->get($cacheid);
//echo $val;
$memcacheing = 1;
//$mem->set($cacheid, '', 0, $viewObj->cache_lifetime);
if ($memcacheing && $assign = $mem->get($cacheid)) {
    echo 'mem获取到缓存';
    print_r($assign);
    $viewObj->assign('title', $assign['title'])
            ->assign('num', $assign['num'])
            ->assign('time', $assign['time'])   
            ->assign('accountsRs', $assign['accountsRs'])     
            ->assign('arr', $assign['arr']); 
}else{
    if (!$viewObj->is_cached('view', $cacheid)) {
        $title = 'smarty和memcahce测试';
        $num = rand(0,10);  
        $arr = array('hello', 'world', '齐', '圣', '福'); 
        $viewObj->assign('title', $title)
                ->assign('num', $num)
                ->assign('time', time())   
                ->assign('accountsRs', $accountsRs)     
                ->assign('arr', $arr); 
        $assign = array();     
        $assign['title'] = $title;
        $assign['num'] = $num;
        $assign['time'] = time();   
        $assign['accountsRs'] = $accountsRs;    
        $assign['arr'] = $arr;
        echo '建立缓存';
        print_r($assign);
        $mem->set($cacheid, $assign, true, $viewObj->cache_lifetime); //键、值、是否压缩、缓存时间
    }
} 
$mem->close();   
$viewObj->display('view',$cacheid);  
